package me.zhengjie.config;

import java.util.Observable;
import java.util.Observer;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.heshuo.amm.service.FlightConfigServiceImpl;
import com.heshuo.amm.service.IFlightConfigService;
import com.heshuo.amm.service.IMETAuthorityService;
import com.heshuo.amm.service.IMETMessageService;
import com.heshuo.amm.service.IReceiveMessageService;
import com.heshuo.amm.service.IReplaceAirportService;
import com.heshuo.amm.service.ISimpleLanguageService;
import com.heshuo.amm.service.ISystemConfigService;
import com.heshuo.amm.service.ITakeoffService;
import com.heshuo.amm.service.METAuthorityServiceImpl;
import com.heshuo.amm.service.METMessageServiceImpl;
import com.heshuo.amm.service.ReceiveMessageServiceImpl;
import com.heshuo.amm.service.ReplaceAirportServiceImpl;
import com.heshuo.amm.service.SimpleLanguageServiceImpl;
import com.heshuo.amm.service.SystemConfigServiceImpl;
import com.heshuo.amm.service.TakeoffServiceImpl;
import com.heshuo.amm.service.remind.RemindTimer;
import com.heshuo.amm.service.remind.SendMessageRemind;

import me.zhengjie.modules.monitor.config.LoggerQueue;
import me.zhengjie.modules.monitor.domain.LogMessage;

@Configuration
public class AmmConfig  implements ApplicationRunner {

	@Bean
	IFlightConfigService getIFlightConfigService() {
		IFlightConfigService fcs = new FlightConfigServiceImpl();
		return fcs;
	}

	@Bean
	ISystemConfigService getISystemConfigService() {
		return new SystemConfigServiceImpl();
	}

	@Bean
	ITakeoffService getITakeoffService() {
		return new TakeoffServiceImpl();
	}

	@Bean
	ISimpleLanguageService getISimpleLanguageService() {
		// 简语
		return new SimpleLanguageServiceImpl();
	}

	@Bean
	IReplaceAirportService getIReplaceAirportService() {
		// 代发机场
		return new ReplaceAirportServiceImpl();
	}

	@Bean
	IMETAuthorityService getIMETAuthorityService() {
		// 机场库
		return new METAuthorityServiceImpl();
	}
	@Bean
	IMETMessageService getIMETMessageService(){
		return new METMessageServiceImpl();
	}
	@Bean
	IReceiveMessageService getIReceiveMessageService(){
		return new ReceiveMessageServiceImpl();
	}
	//系统启动后运行
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		RemindTimer rt = RemindTimer.getInstance();
		rt.addObserver(new Observer() {
			
			@Override
			public void update(Observable o, Object arg) {
				LogMessage log = new LogMessage(((SendMessageRemind) arg).getTitle(),null,null,"sendMessageNotice","OTHER");
				LoggerQueue.getInstance().push(log);
			}
		});
		rt.run();
	}
	
//	@Bean
//	MultipartConfigElement multipartConfigElement() {
//		MultipartConfigFactory factory = new MultipartConfigFactory(); // 设置路径xxx
////		System.getProperty("user.dir");
//		factory.setLocation(System.getProperty("user.dir"));
//		return factory.createMultipartConfig();
//	}
}
